package model.bean;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@Entity
@Table(name="t_menu")
public class Menu {

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "geradorMenu")
	@SequenceGenerator(name = "geradorMenu", sequenceName = "sequence_menu", allocationSize=1)
	@Column(name="id_menu")
	private Long id;
	
	@Column(name="nome_menu",length=25)
	private String nomeMenu;
	
	@OneToMany(mappedBy="menu")
	@Cascade({CascadeType.ALL, CascadeType.DELETE_ORPHAN})
	private List<ItemMenu> itensMenu;
	
	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name="t_grupo_usuario_menu",
			   joinColumns=@JoinColumn(name="id_menu"),
	           inverseJoinColumns=@JoinColumn(name="id_grupo_usuario"))
	           @Cascade(CascadeType.SAVE_UPDATE)
	private List<GrupoUsuario> gruposUsuarios;

	public List<ItemMenu> getItensMenu() {
		return itensMenu;
	}

	public void setItensMenu(List<ItemMenu> itensMenu) {
		this.itensMenu = itensMenu;
	}

	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	
	public String getNomeMenu() {
		return nomeMenu;
	}
	
	public void setNomeMenu(String nomeMenu) {
		this.nomeMenu = nomeMenu;
	}

	public List<GrupoUsuario> getGruposUsuarios() {
		return gruposUsuarios;
	}

	public void setGruposUsuarios(List<GrupoUsuario> gruposUsuarios) {
		this.gruposUsuarios = gruposUsuarios;
	}
}
